/*
 * @(#)CachePlugIn.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.core.plugin;

import java.util.Properties;

import org.w3c.dom.Node;

import com.nhncorp.lucy.common.plugin.AbstractPlugIn;
import com.nhncorp.lucy.common.plugin.PlugInException;
import com.nhncorp.usf.core.Constants;
import com.nhncorp.usf.core.cache.CacheInitializeException;
import com.nhncorp.usf.core.cache.CacheManager;

/**
 * @author Web Platform Development Team
 */
public class CachePlugIn extends AbstractPlugIn {
    private String className;
    private String defaultExpire;
    private String size;

    /**
     * Gets the class name.
     *
     * @return the class name
     */
    public String getClassName() {
        return className;
    }

    /**
     * Sets the class name.
     *
     * @param className the new class name
     */
    public void setClassName(String className) {
        this.className = className;
    }

    /**
     * Gets the default expire.
     *
     * @return the default expire
     */
    public String getDefaultExpire() {
        return defaultExpire;
    }

    /**
     * Sets the default expire.
     *
     * @param defaultExpire the new default expire
     */
    public void setDefaultExpire(String defaultExpire) {
        this.defaultExpire = defaultExpire;
    }

    /**
     * Gets the size.
     *
     * @return the size
     */
    public String getSize() {
        return size;
    }

    /**
     * Sets the size.
     *
     * @param size the new size
     */
    public void setSize(String size) {
        this.size = size;
    }

    /**
     *
     * @param node the Node
     * @return boolean the parsing success
     * @throws PlugInException the PlugInException
     */
    @Override
    public boolean build(Node node) throws PlugInException {
        return true;
    }

    /**
     *
     * @throws PlugInException the PlugInException
     */
    @Override
    public void destroy() throws PlugInException {
        CacheManager.getInstance().shutdown();
    }

    /**
     *
     * @throws PlugInException the PlugInException
     */
    @Override
    public void init() throws PlugInException {
        Properties properties = new Properties();

        if (className != null) {
            properties.setProperty(Constants.CACHE_CLASS_PROPERTY_NAME, className);
        }

        if (defaultExpire != null) {
            properties.setProperty("defaultExpire", defaultExpire);
        }

        if (size != null) {
            properties.setProperty("size", size);
        }

        try {
            CacheManager.getInstance().initialize(properties);
        } catch (CacheInitializeException e) {
            throw new PlugInException(e);
        }
    }
}
